var $newfeeds 	=  $('#newfeed'),
	serverUrl	= 'http://localhost/zigo/server/home.php/';
Feed = Backbone.Model.extend({
	defaults: {
		place_id: '',
		detail_comment: '',
		place_name: '',
		user_id_zing: '',
		user_avatar_zing: '',
		user_display_name: '',
		user_name_zing: ''
	},
	urlRoot: serverUrl + 'newfeed'
});

FeedView = Backbone.View.extend({
	tagName: 'div',
	//className: 'topplace-item',
	initialize: function() {
		this.render = _.bind(this.render, this);
		this.template = _.template($('#newfeed-item').html());
		//this.model.bind('change', this.render);
	},
	render: function() {
		this.$el.html(this.template(this.model.attributes));
		return this;
	}
});

FeedCollection = Backbone.Collection.extend({
	model: Feed,
	url: serverUrl + 'newfeed'
});

FeedList = Backbone.View.extend({
	initialize: function() {
		_(this).bindAll('add');

		this._newfeeds = [];
		
		this.collection.each(this.add);
		
		this.collection.bind('add', this.add);
	},
	render: function() {
		this._rendered = true;
		this.$el.empty();
		_(this._newfeeds).each(function(item) {
			$newfeeds.append(item.render().el);
		});
	},
	add: function(feed) {
		var newFeedItem = new FeedView({model: feed});

		this._newfeeds.push(newFeedItem);

		if (this._rendered) {
			this.$el.append(newFeedItem.render().el);
		}
	}
});